package com.neo4j.neo4jcloud.controller;

import com.alibaba.fastjson.JSONObject;
import com.neo4j.neo4jcloud.entity.CompanyGraph;
import com.neo4j.neo4jcloud.entity.SupplyRelationShip;
import com.neo4j.neo4jcloud.service.SupplyRelationShipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

/**
 * @author kabuqinuo
 * @date 2020/3/26 14:44
 */
@RestController
@RequestMapping(value = "/supplyRelationShip")
public class SupplyRelationShipController {

    @Autowired
    private SupplyRelationShipService supplyRelationShipService;

    @PostMapping
    public ResponseEntity<SupplyRelationShip> add(HttpServletRequest request, @RequestBody SupplyRelationShip supplyRelationShip, HttpServletResponse response){
        return ResponseEntity.ok(supplyRelationShipService.addSupplyRelationShip(supplyRelationShip));
    }

    @GetMapping
    public ResponseEntity<SupplyRelationShip> findOne(HttpServletRequest request, @RequestParam(value = "id") Long id, HttpServletResponse response){
        return ResponseEntity.ok(supplyRelationShipService.findOneBySupplyRelationShipId(id));
    }

    @DeleteMapping
    public String deleteOne(HttpServletRequest request, @RequestParam(value = "id") Long id, HttpServletResponse response){
        supplyRelationShipService.deleteOneBySupplyRelationShipId(id);
        return "success";
    }

    @GetMapping("/all")
    public ResponseEntity<List<SupplyRelationShip>> findAll(HttpServletRequest request, HttpServletResponse response){
        return ResponseEntity.ok(supplyRelationShipService.findAllSupply());
    }

    @GetMapping("/findByNodeId")
    public ResponseEntity<List<SupplyRelationShip>> findByNodeId(HttpServletRequest request, @RequestParam(value = "nodeId") String nodeId,
                                                                 HttpServletResponse response){
        return ResponseEntity.ok(supplyRelationShipService.findASupplyByNodeId(nodeId));
    }

    @GetMapping("/make")
    public String makeData(HttpServletRequest request, HttpServletResponse response){
        supplyRelationShipService.makeDataBySupplyRelationShip();
        return "success";
    }

    @GetMapping("/makeMore")
    public String makeDataMore(HttpServletRequest request, HttpServletResponse response){
        supplyRelationShipService.makeDataMoreBySupplyRelationShip();
        return "success";
    }
}
